package com.dance.webflux.reactor8;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class TestReactor {

    public static void main(String[] args) {
        /*
         * just 方法直接声明
         */
        Flux<Integer> flux = Flux.just(1, 2, 3);

        Mono<Integer> mono = Mono.just(1);

        // 订阅数据流
        flux.subscribe(x -> System.out.print(x + " "));
        System.out.println();
        mono.subscribe(System.out::println);

        // 其他方法
        // 数组
        Integer[] array = new Integer[]{1,2,3,4};
        Flux<Integer> flux1 = Flux.fromArray(array);
        // 集合
        List<Integer> array2 = Arrays.asList(1, 2, 3, 4);
        Flux<Integer> flux2 = Flux.fromIterable(array2);
        // Stream
        Stream<Integer> stream = array2.stream();
        Flux<Integer> flux3 = Flux.fromStream(stream);
        // 供给型函数式接口Stream
        Flux<Integer> tFlux = Flux.fromStream(() -> Stream.of(1, 2, 3));

    }

}
